import {Component, ContentChild, EventEmitter, Input, Output, TemplateRef, ViewChild} from '@angular/core';
import {NavController, Select} from "ionic-angular";

@Component({
    selector: 'client-list-item',
    templateUrl: 'client-list-item.html'
})
export class ClientListItemComponent {
    currentClient;
    currentMobileList;
    currentMobile;

    @ViewChild('selectMobile') selectMobile: Select;
    @Output() callNumber;
    @Output() searched;
    @Input()item:any;
    //显示投被标识
    @Input()isShowIp:boolean;
    searchKeyword;

    constructor(
        public navCtrl: NavController,
        ) {
        this.callNumber = new EventEmitter<any>();
        this.searched = new EventEmitter<any>();
    }

    //到客户详情
    goToDetail(item) {
        if(item.leadId){
            this.navCtrl.push('ClientDetailPage', {
                clientNum: item.leadId,
                leads: true
            })
        }else{
            this.navCtrl.push('HolderClientDetailPage', {
                clientNum: item.clientId,
                role:item.clientRole
            });
        }
    }

    funcWrapperClick(e){
        e.stopPropagation();
    }

    /**
     * 打电话
     */
    callClickHandle(e,item) {
        e.stopPropagation();
        e.preventDefault();
        this.callNumber.emit(item);
    }


    /**
     * 输入框键盘事件
     * @param e
     */
    inputKeyUp(e) {
        if ('Enter' === e.key || 13 === e.keyCode) {
            this.searched.emit(this.searchKeyword);
        }
    }

    searchHandle(ev) {
        ev.preventDefault();
        ev.stopPropagation();
        this.inputKeyUp({key: 'Enter'});
    }


}
